  //近期在线人数统计树状图

var date=new Date;  
var year=date.getFullYear();   
var month=date.getMonth()+1;
var text;
var testt;
var time;//获取选择的时间
var name;
var daytime=[];//装入分割后的时间
var odata=[];
var tdata=[];
var chart;
var dateTime=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();

$(function () {

	$(".day").val(dateTime);
	time=$(".day").val();
	daytime=time.split("-");//分割时间
	year=daytime[0];
	month=daytime[1];
	str="day";
	data(str,time);
	target=$("#sr_day");
	textt='每天上线人数';
	name=year+'-'+month;
	tu(odata,tdata,textt,name);

	function data(str){
		odata=[];
		tdata=[];
		$.ajax({
			   type: "post",
			   url: "online",
			   data:{  
	                "data":str,
	                "time":time
	            },
			   async: false,
			   success: function(map){
				   text=$.parseJSON(map);
		            for (var prop in text){
		            	odata.push(prop);
		            	tdata.push( text[prop]);
		            }
			   }
			});
	};

	function tu(odata,tdata,textt,name){
		chart = Highcharts.chart('container', {
	        title: {
	            text: textt
	        },
	        subtitle: {
	            text: '普通的'
	        },
	        xAxis: {
	            categories:odata
	        },
	        series: [{
	            type: 'column',
	            colorByPoint: true,
	            name: name,
	            data: tdata,
	            showInLegend: false
	        }]
	    });
	    $('#plain').click(function () {
	    	chart.update({
	            chart: {
	                inverted: false,
	                polar: false
	            },
	            subtitle: {
	                text: '普通的'
	            }
	        });
	    });
	    $('#inverted').click(function () {
	        // chart.update 支持全部属性动态更新
	    	chart.update({
	            chart: {
	                inverted: true,
	                polar: false
	            },
	            subtitle: {
	                text: '反转'
	            }
	        });

	    });
	    $('#polar').click(function () {
	    	chart.update({
	            chart: {
	                inverted: false,
	                polar: true
	            },
	            subtitle: {
	                text: '极地图'
	            }
	        });
	    });
	}
	//按天
	$("#day").on("click",function(){
		daytime=[];
		var time=$(".day").val();
		daytime=time.split("-");//分割时间
		year=daytime[0];
		month=daytime[1];
		str="day";
		data(str);
		textt='每天上线人数';
		name=year+'-'+month;
		tu(odata,tdata,textt,name);
	});
	//按月
	$("#month").on("click",function(){
		
		daytime=[];
		var time=$(".day").val();
		daytime=time.split("-");//分割时间
		year=daytime[0];
		str="month";
		data(str,time);
		textt='每月上线人数';
		name=year;
		tu(odata,tdata,textt,name);
	});
	//按年
	$("#year").on("click",function(){
		daytime=[];
		var time=$(".day").val();
		str="year";
		data(str,time);
		textt='每年上线人数';
		name="";
		tu(odata,tdata,textt,name);
	});
	
}); 
 
